Set the digraph title to "Agent Event Flow".

Akinori MUSHA 10 years ago
parent
commit
53cb86c6de
2 changed files with 13 additions and 9 deletions
  1. 11 7
      app/helpers/dot_helper.rb
  2. 2 2
      spec/helpers/dot_helper_spec.rb

+ 11 - 7
app/helpers/dot_helper.rb

@@ -57,6 +57,13 @@ module DotHelper
57 57
       end
58 58
     end
59 59
 
60
+    def ids(values)
61
+      values.each_with_index { |id, i|
62
+        raw ' ' if i > 0
63
+        id id
64
+      }
65
+    end
66
+
60 67
     def attr_list(attrs = nil)
61 68
       return if attrs.nil?
62 69
       attrs = attrs.select { |key, value| value.present? }
@@ -86,16 +93,13 @@ module DotHelper
86 93
     end
87 94
 
88 95
     def statement(ids, attrs = nil)
89
-      Array(ids).each_with_index { |id, i|
90
-        raw ' ' if i > 0
91
-        id id
92
-      }
96
+      ids Array(ids)
93 97
       attr_list attrs
94 98
       raw ';'
95 99
     end
96 100
 
97
-    def block(title, &block)
98
-      raw title
101
+    def block(*ids, &block)
102
+      ids ids
99 103
       raw '{'
100 104
       block.call
101 105
       raw '}'
@@ -137,7 +141,7 @@ module DotHelper
137 141
              color: (@disabled if agent.disabled? || receiver.disabled?))
138 142
       end
139 143
 
140
-      block('digraph foo') {
144
+      block('digraph', 'Agent Event Flow') {
141 145
         # statement 'graph', rankdir: 'LR'
142 146
         statement 'node',
143 147
                   shape: 'box',

+ 2 - 2
spec/helpers/dot_helper_spec.rb

@@ -56,7 +56,7 @@ describe DotHelper do
56 56
       it "generates a DOT script" do
57 57
         agents_dot(@agents).should =~ %r{
58 58
           \A
59
-          digraph \s foo \{
59
+          digraph \x20 "Agent \x20 Event \x20 Flow" \{
60 60
             node \[ [^\]]+ \];
61 61
             (?<foo>\w+) \[label=foo\];
62 62
             \k<foo> -> (?<bar1>\w+) \[style=dashed\];
@@ -73,7 +73,7 @@ describe DotHelper do
73 73
       it "generates a richer DOT script" do
74 74
         agents_dot(@agents, true).should =~ %r{
75 75
           \A
76
-          digraph \s foo \{
76
+          digraph \x20 "Agent \x20 Event \x20 Flow" \{
77 77
             node \[ [^\]]+ \];
78 78
             (?<foo>\w+) \[label=foo,URL="#{Regexp.quote(agent_path(@foo))}"\];
79 79
             \k<foo> -> (?<bar1>\w+) \[style=dashed\];